using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SpringWaterDataAccess;
using Utilities;

namespace sow
{
	/// <summary>
	/// Summary description for admin04.
	/// </summary>
	public partial class admin04 : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			// Don't remove this check. Otherwise, the CheckBoxes in Repeater will always have
			// Checked as False. It took me long time to figure it out. -xue
			if (!IsPostBack) 
			{
				BindDataForRepeater();
			}
		}

		private void BindDataForRepeater()
		{
			// Step 1: retrieve dataset from SQL for the articles, here we construct it on the fly
			DataSet ds = UserObject.GetPublishedWords();		
			//Step 2: need paging, which can be in the header

			// Step 3: Binding it and refresh, and that is
			MyRepeater.DataSource = ds.Tables[0].DefaultView;
			MyRepeater.DataBind();
		}

		public string getCategoryFromID(string ID)
		{
			return Helper.getCategoryFromID(ID);
		}

		public static string getPartnerFromID(string id)
		{
			
			return UserObject.getPartner(int.Parse(id));
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.MyRepeater.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.MyRepeater_ItemCommand);

		}
		#endregion

		private void MyRepeater_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
		{
		
		}

		

		protected void Button1_Click(object sender, System.EventArgs e)
		{

			foreach (RepeaterItem myitem in MyRepeater.Items) 
			{
				
				foreach (Control c in myitem.Controls) 
				{

					if (c is CheckBox ) 
					{ 
						CheckBox cb = (CheckBox)c;
						
						if ((cb.Checked)) 
						{
							// Each row has a invisible Label for dispalying word ID
							Label idLabel = (Label)myitem.FindControl("Label1");

							if (idLabel != null) 
							{
								// Change status from database
								UserObject.ChangeWordStatus(
									Convert.ToInt32(idLabel.Text), 
									0,
									"Archived"); 

							}
						}
					}
					
				}
			}

			// Refresh data from database
			BindDataForRepeater();
	} //Button1-Click 

	}
}
